module JobsHelper
  include Utils::Text

  def job_section(title,data,list = false, note = nil)
    rvalue = ""
    if list
      data = format_list(data) 
    else
      data = format_paragraph(data)
    end
    descr = (note ? "<br/><i>#{note}</i>" : "")
    unless empty_or_nil?(data)
      rvalue = <<-HTML
        <span class="job_section">#{title}:#{descr}</span> <br/>
          #{data}
      HTML
    end
    rvalue
  end

  private
    def format_list(data)
      return "" if empty_or_nil?(data)
      rvalue = "<ul class=\"criteria\">"
      lines = data.split("\n")
      lines.each do |line|
        next if line.strip.length == 0
        rvalue << "<li>" << line << "</li>"
      end
      rvalue << "</ul>"
      rvalue
    end

    def format_paragraph(data)
      return "" if empty_or_nil?(data)
      return <<-HTML
        <p class="job_description">
          #{h(data)}
        </p><br/>
      HTML
    end
end
